import { DEFAULT_OPTS } from '@/settings'
import { defHttp } from '@/utils/http/axios'
import { IDictionaryOpts, IDictionaryResp } from './model'

enum APIS {
  'DICT' = '/dict',
  'DICT_LIST' = '/dict/list',
  'DICT_OPTS' = '/dict/opts'
}

/** 获取字典列表 */
export function getDictList(type?: string) {
  return defHttp.get<IDictionaryResp[]>({
    url: APIS.DICT_LIST,
    params: {
      type
    }
  }, DEFAULT_OPTS)
}

/** 新增数据字典 */
export function addDictionary(data: Omit<IDictionaryResp, 'id' | 'createDate'>) {
  return defHttp.post({
    url: APIS.DICT,
    data
  }, DEFAULT_OPTS)
}

/** 编辑数据字典 */
export function editDictionary(data: Omit<IDictionaryResp, 'createDate'>) {
  return defHttp.put({
    url: APIS.DICT,
    data
  }, DEFAULT_OPTS)
}

/** 删除数据字典 */
export function deleteDictionary(id: string) {
  return defHttp.delete({
    url: APIS.DICT + `/${id}`
  }, DEFAULT_OPTS)
}

/** 获取下拉选项 */
export function getDictOpts(type: string) {
  return defHttp.get<IDictionaryOpts[]>({
    url: APIS.DICT_OPTS,
    params: {
      type
    }
  }, DEFAULT_OPTS)
}
 
